home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / HippoDraw / HippoDrawSrc1.1 / Hippo.subproj / FineSlider.m < prev    next >
Encoding:
Text File  |  1992-04-25  |  1.6 KB  |  65 lines

  1. /* FineSlider.m        by Mike Gravina        December 1991
  2.  * A subclass of Slider that allows Alternate key to slow slider 
  3.  * down by scale factor
  4.  *
  5.  * Copyright (C)  1991  The Board of Trustees of
  6.  * The Leland Stanford Junior University.  All Rights Reserved.
  7.  */
  8.  
  9. #import "FineSlider.h"
  10.  
  11. const char FineSlider_h_rcsid[] = FINESLIDER_H_ID;
  12. const char FineSlider_m_rcsid[] = "$Id: FineSlider.m,v 1.4 1991/12/24 14:37:00 pfkeb Rel $";
  13.  
  14.  
  15. #import <appkit/Application.h>
  16.  
  17. @implementation FineSlider
  18. + new
  19. {
  20.     self = [super new];
  21.     inAltSequence = NO;
  22.     offset = 0.0;
  23.     scaleFactor = 20.0;
  24.     return self;
  25. }
  26.  
  27.  
  28. - (float) floatValue
  29. {
  30.     NXEvent            *thisEvent;
  31.     float               newValue;
  32.  
  33.     newValue = [super floatValue];
  34.     thisEvent = [NXApp currentEvent];
  35.     if (thisEvent->flags & NX_ALTERNATEMASK) {
  36.     if (!inAltSequence) {
  37.         inAltSequence = YES;
  38.         centerValue = newValue - offset;    /* save rubberband end point */
  39.         returnValue = centerValue;
  40.     } else {
  41.         returnValue = centerValue + (newValue - centerValue) / scaleFactor;
  42.         offset = newValue - returnValue;    /* save rubberband's new
  43.                          * length */
  44.     }
  45.     } else {
  46.     inAltSequence = NO;
  47.     returnValue = newValue - offset;    /* rubberband treated as
  48.                          * rigid */
  49.     }
  50.     if (thisEvent->type == NX_LMOUSEUP) {
  51.     centerValue = returnValue;    /* set rubberband end point to
  52.                      * current point */
  53.     offset = 0.0;        /* set rubberband length to zero */
  54.     }
  55.     [super setFloatValue:returnValue];
  56.     return returnValue;
  57. }
  58.  
  59. - setScaleFactor:(float) aFloat
  60. {
  61.     scaleFactor = aFloat;
  62.     return self;
  63. }
  64. @end
  65.